package com.flyme.module.base.provider.service.impl;

import com.flyme.common.core.model.query.CriteriaQuery;
import com.flyme.common.core.model.query.PagerInfo;
import com.flyme.common.core.model.query.PqGrid;
import com.flyme.core.base.supper.entity.EntityMap;
import com.flyme.core.base.supper.service.impl.BaseServiceImpl;
import com.flyme.module.base.client.entity.SysInvoice;
import com.flyme.module.base.provider.mapper.SysInvoiceMapper;
import com.flyme.module.base.provider.service.SysInvoiceService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author: zyf
 * @date: 2018/10/24 16:33
 * @description:
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SysInvoiceServiceImpl extends BaseServiceImpl<SysInvoiceMapper, SysInvoice> implements SysInvoiceService {

    /**
     * 查询用户
     */
    public List<EntityMap> selectByUser(String userId, PagerInfo pagerInfo){
        CriteriaQuery queryWrapper = new CriteriaQuery<EntityMap>(pagerInfo);
        queryWrapper.select("i.*,CASE WHEN i.invoiceType=1 THEN '个人发票' ELSE '企业发票' END typeName,o.orderNo");
        queryWrapper.eq("i.userId", userId);
        queryWrapper.orderByDesc("createTime");
        queryWrapper.createAlias("order", "o");
        List<EntityMap> list = (List<EntityMap>) pageList(queryWrapper).getRows();
        return list;
    }

    /**
     * 网站查询用户
     */
    public PqGrid selectByUserWeb(String userId, PagerInfo pagerInfo){
        CriteriaQuery queryWrapper = new CriteriaQuery<EntityMap>(pagerInfo);
        queryWrapper.select("i.*,CASE WHEN i.invoiceType=1 THEN '个人发票' ELSE '企业发票' END typeName,o.orderNo");
        queryWrapper.eq("i.userId", userId);
        queryWrapper.orderByDesc("createTime");
        queryWrapper.createAlias("order", "o");
        return pageList(queryWrapper);
    }

}
